package com.usian.admin.controller;

import com.usian.admin.service.AdChannelService;
import com.usian.apis.admin.AdChannelControllerApi;
import com.usian.model.admin.pojos.AdChannel;
import com.usian.model.common.dtos.ChannelDto;
import com.usian.model.common.dtos.ResponseResult;
import com.usian.model.common.enums.AppHttpCodeEnum;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
@Api(tags={"用户接口"}, value="用户接口Controller")
@RestController
@RequestMapping("/api/v1/channel")
public class AdChannelController implements AdChannelControllerApi {

    @Autowired
    private AdChannelService channelService;
    @ApiOperation(value = "查询列表", notes = "徐寒哥哥")
    @PostMapping("/list")
    @Override
    public ResponseResult findByNameAndPage(@RequestBody ChannelDto dto) {
        return channelService.findByNameAndPage(dto);
    }
    @ApiOperation(value = "添加修改", notes = "徐寒哥哥")
    @PostMapping("/saveOrUpdate")
    @Override
    public ResponseResult saveOrUpdateChannel(@RequestBody AdChannel adChannelDto) {
        if (adChannelDto.getId() == null) {
            adChannelDto.setCreatedTime(new Date());
            channelService.save(adChannelDto);
            return new ResponseResult();
        } else if (adChannelDto.getId()!=null){
            channelService.updateById(adChannelDto);
            return new ResponseResult();
        }
        return ResponseResult.errorResult(AppHttpCodeEnum.PARAM_INVALID);
    }
    @ApiOperation(value = "删除", notes = "徐寒哥哥")
    @DeleteMapping("delete")
    @Override
    public ResponseResult DeleteChannel(Integer id) {
        channelService.removeById(id);
        return new ResponseResult();
    }




}